home *** CD-ROM | disk | FTP | other *** search
- /*
- File: domouse.c
-
- Contains: mouse tracking routines
-
- Written by: Mary Chan
-
- Copyright: © 1990 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #pragma load <header.dump>
- #include "TMIntf.h"
- #include "globals.h"
-
-
- extern Rect visCacheRect;
- extern Point mycellSize;
- extern Point myslop;
-
- /******************************************************************
- * SwapPoint
- * - swap the two pass in starting and end point so that endptr > startptr.
- *
- * inputs:
- * startptr - starting point of the selection, top left, expect the
- * address of the point.
- * endptr - ending point of the selection, bottom right, expects address
- *
- ******************************************************************/
- SwapPoint( startptr, endptr )
- Point *startptr ;
- Point *endptr ;
- {
- Point tempptr ;
-
- if ( ( endptr->v < startptr->v) ||
- ( endptr->v == startptr->v && endptr->h < startptr->h )
- )
- {
- tempptr = *startptr ;
- *startptr = *endptr ;
- *endptr = tempptr ;
- }
- }
-
-
-
- /******************************************************************
- * GetRegion
- * - return a region handle which encloses the region inside
- * the two diagonal points. Expects the points to be at the
- * cell boundary.
- *
- * inputs:
- * regionhdl - region handle
- * startptr - starting point of the selection, top left, expect the actual point
- * not the address of the point, less dereference.
- * endptr - ending point of the selection, bottom right
- *
- ******************************************************************/
- GetRegion( regionhdl, startptr, endptr )
- RgnHandle regionhdl ;
- Point startptr;
- Point endptr ;
- {
- Rect tempRect;
- Point rowstartptr;
- Point rowendptr ;
- short cellheight ;
- short right;
- short left;
- short rowselected ;
-
- cellheight = mycellSize.v ;
-
- left = _CACHEDESTRECT.left + myslop.h;
- right = _CACHEDESTRECT.right - myslop.h;
-
- SwapPoint( &startptr, &endptr ) ;
-
- /* rowselected is at least one */
- rowselected = (endptr.v - startptr.v) / cellheight + 1;
-
- OpenRgn();
-
- if ( rowselected == 1)
- {
- rowendptr = endptr ;
- if ( rowendptr.v == startptr.v )
- rowendptr.v += cellheight ;
- Pt2Rect(startptr,rowendptr,&tempRect);
- FrameRect(&tempRect);
- }
- else
- {
- rowendptr.h = right ;
- rowendptr.v = startptr.v + cellheight ;
- Pt2Rect(startptr,rowendptr,&tempRect);
- FrameRect(&tempRect);
-
- if ( rowselected > 2 )
- {
- rowstartptr.h = left ;
- rowstartptr.v = rowendptr.v ;
- rowendptr.v = endptr.v ;
- Pt2Rect(rowstartptr,rowendptr,&tempRect);
- FrameRect(&tempRect);
- } /* if ( rowselected > 2 ) */
- rowstartptr.v = endptr.v ;
- rowstartptr.h = left;
- endptr.v += cellheight ;
- Pt2Rect(rowstartptr,endptr,&tempRect);
- FrameRect(&tempRect);
- }
- CloseRgn( regionhdl );
- }
-
-
- /******************************************************************
- * CombineNewOldrgn()
- * - select the conbination region of oldregion and newregion
- *
- * inputs:
- * newregion - new region to be combine and invert ( or select )
- * oldregion - old region to be combine and invert ( or select )
- *
- ******************************************************************/
- CombineNewOldrgn( newregion, oldregion )
- RgnHandle newregion ;
- RgnHandle oldregion ;
- {
- BitClr( (Ptr) HiliteMode, pHiliteBit ) ;
- XorRgn(newregion,oldregion,oldregion);
- InvertRgn(oldregion);
- }
-
-
- /******************************************************************
- * Cellboundary
- * - return the passed in point at the cell boundary
- *
- * inputs:
- * where - mouse point
- *
- ******************************************************************/
- Cellboundary( where )
- Point *where;
- {
- short leftover;
- short halfcellwidth;
- short cellwidth;
- Boolean DonewithH;
- short left;
- short right;
- short bottom;
- short top;
-
- left = _CACHEDESTRECT.left + myslop.h;
- if ( where->v >= visCacheRect.bottom - CACHBOTTOMSLOP)
- {
- /* pin .h to the lower right bottom */
- where->h = _CACHEDESTRECT.right - myslop.h;
- DonewithH = true;
- }
- else if ( where->v <= visCacheRect.top )
- {
- where->h = left;
- DonewithH = true;
- }
-
- top = _CACHEDESTRECT.top;
- bottom = _CACHEDESTRECT.bottom - CACHBOTTOMSLOP;
-
- if ( where->v > bottom )
- {
- where->v = bottom-mycellSize.v;
- if ( !DonewithH )
- {
- /* pin .h to the lower right bottom */
- where->h = _CACHEDESTRECT.right - myslop.h;
- DonewithH = true;
- } /* if ( !DonewithH ) */
- }
- else if ( where->v < top )
- {
- where->v = top;
- if ( !DonewithH )
- {
- /* pin .h to the lower right bottom */
- where->h = left;
- DonewithH = true;
- } /* if ( !DonewithH ) */
- }
- else
- {
- where->v -= _CACHEDESTRECT.top ;
- leftover = where->v % mycellSize.v ;
- where->v -= leftover ;
- where->v += _CACHEDESTRECT.top;
- }
- if ( !DonewithH )
- {
- if ( (where->h - left ) < 0 )
- {
- where->h = left;
- return;
- }
- else
- {
- right = _CACHEDESTRECT.right - myslop.h;
- if ( where->h > right )
- {
- where->h = right;
- return;
- }
- }
- cellwidth = mycellSize.h;
- where->h -= left;
- leftover = where->h % cellwidth ;
- where->h -= leftover ;
- where->h += left;
- halfcellwidth = cellwidth/2; /* get half of the cell width */
- if ( cellwidth % 2 )
- halfcellwidth++;
- if ( leftover > halfcellwidth ) /* is the point ends at more than half way thru the cell */
- {
- where->h += cellwidth ; /* select the whole cell if so */
- }
- } /* if ( !DonewithH ) */
- }
-
-
- /******************************************************************
- * GetCell()
- * - return the cell in rows & columns for the passed in cell's location
- *
- * inputs:
- * location - cell's location in pixel
- * cellsize - current cellsize
- *
- * returns:
- * cell's location in row & columns
- *
- ******************************************************************/
- Point GetCell( location, cellsize )
- Point location;
- Point cellsize;
- {
- Point cell;
-
- /* which row */
- location.v -= _CACHEDESTRECT.top;
- cell.v = location.v / cellsize.v;
- /* which col */
- location.h -= _CACHEDESTRECT.left + myslop.h;
- cell.h = location.h / cellsize.h;
- return cell;
- }
-
- /******************************************************************
- * GetCellPoint()
- * - return the cell's location in pixel
- *
- * inputs:
- * cell - cell's location in rows and columns
- * cellsize - current cellsize
- * returns:
- * cell's location in pixel
- *
- ******************************************************************/
- Point GetCellPoint( cell, cellsize )
- Point cell;
- Point cellsize;
- {
- Point location;
-
- location.v = cell.v * cellsize.v + _CACHEDESTRECT.top;
- location.h = cell.h * cellsize.h + _CACHEDESTRECT.left + myslop.h;
- return location;
- }